﻿//========================================================= 
/**@file random.h
 * @brief 返回随机数的监控项
 * 
 * @date 2018-08-10   08:39:32
 * @author Zhyioo 
 * @version 1.0
 */ 
//--------------------------------------------------------- 
#ifndef _LIBZHOUYB_RANDOM_H_
#define _LIBZHOUYB_RANDOM_H_
//--------------------------------------------------------- 
#include "../../include/Base.h"
//--------------------------------------------------------- 
namespace zhou_yb {
namespace wrapper {
namespace zabbix_extractor {
//--------------------------------------------------------- 
/**
 * @brief 返回随机数的监控项
 * @date 2018-08-10 08:42
 */
class random_monitor
{
public:
    typedef int value_type;

    static value_type execute(int minNum, int maxNum)
    {
        srand(Timer::TimeTick());
        return (rand() % (maxNum - minNum + 1) + minNum);
    }
    static value_type execute(int argc, const char* argv[])
    {
        int minNum = 0;
        int maxNum = 100;
        
        /* 根据命令行参数设置随机数范围 */
        switch(argc)
        {
        case 2:
            maxNum = ArgConvert::FromString<int>(argv[1]);
            break;
        case 3:
            minNum = ArgConvert::FromString<int>(argv[1]);
            maxNum = ArgConvert::FromString<int>(argv[2]);
            break;
        }
        return execute(minNum, maxNum);
    }
};
//--------------------------------------------------------- 
} // namespace zabbix_extractor 
} // namespace wrapper
} // namespace zhou_yb 
//--------------------------------------------------------- 
#endif // _LIBZHOUYB_RANDOM_H_
//========================================================= 